package com.shelpe.services.sustainer.development;

import org.springframework.batch.item.ItemProcessor;

import com.shelpe.services.sustainer.client.RankingClient;
import com.shelpe.services.sustainer.entity.jpa.DevelopmentPlan;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Setter
public class ExecuteDevelopmentProcessor implements ItemProcessor<DevelopmentPlan, DevelopmentPlanResult> {

	private RankingClient rankingClient;
	
	@Override
	public DevelopmentPlanResult process(DevelopmentPlan t) throws Exception {
		log.debug("ExecuteDevelopment[{}]: {}", t.getContainerID(), t);
		DevelopmentPlanResult res = new DevelopmentPlanResult();
		res.setPlan(t);
		RankingClient.DevelopmentExecutionRes eRes = this.rankingClient.executeDevelopment(t.getAutoID());
		if(!eRes.isSuccess()){
			log.error("failure: {}", eRes);
		}
		res.setStatus(eRes.isSuccess()?1:-1);
		return res;
	}

}
